package com.yugao.fintech.antelope.base;

import cn.hutool.core.date.DateUtil;
import com.yugao.fintech.antelope.base.model.enums.BoolEnum;
import com.yugao.fintech.framework.assistant.utils.StringUtils;
import org.mapstruct.Named;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public interface BaseAssembly {
    String BOOL_TO_STR = "boolToStr";
    String STR_TO_BOOL = "strToBool";
    String STR_TO_LIST = "strToList";
    String ARRAY_TO_STR = "arrayToStr";
    String ARRAY_TO_LIST = "arrayToList";
    String LIST_TO_STR = "listToStr";
    String LONG_TO_DATE = "longToDate";

    @Named(BOOL_TO_STR)
    default String boolToStr(Boolean value) {
        return BoolEnum.of(value).getCode();
    }

    @Named(STR_TO_BOOL)
    default Boolean strToBool(String value) {
        return BoolEnum.of(value) == BoolEnum.TRUE;
    }

    @Named(STR_TO_LIST)
    default List<String> strToList(String value) {
        return StringUtils.toList(value, ",", String.class);
    }

    @Named(ARRAY_TO_STR)
    default String arrayToStr(Long[] value) {
        return Arrays.stream(value).map(String::valueOf).collect(Collectors.joining(","));
    }

    @Named(LIST_TO_STR)
    default String listToStr(List<String> value) {
        return String.join(",", value);
    }

    @Named(ARRAY_TO_LIST)
    default List<Long> arrayToList(Long[] value) {
        return Arrays.stream(value).collect(Collectors.toList());
    }

    @Named(LONG_TO_DATE)
    default Date longToDate(Long value) {
        return DateUtil.date(value).toJdkDate();
    }
}
